<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>计算器</title>

     <style type="text/css">
        #zt{
            margin: 200px;
            background: wheat;
            width: 400px;
            height: 200px;
            padding: 100px;
            border: 5px salmon solid;
        }
     </style>

    <div id="zt">
    <p>integer one：<input id="num1" type="text"></p>
    <p>integer two：<input id="num2" type="text"></p>
    <p>
        <input type="button" value="plus" onclick="calc(add)">
        <input type="button" value="subtract" onclick="calc(sub)">
        <input type="button" value="ride" onclick="calc(mul)">
        <input type="button" value="divide" onclick="calc(div)">
    </p>
    <p>result：<input id="result" type="text" readonly></p>
    </div>


</head>
<body>
    <script>
       function calc(func){
           var result =document.getElementById('result');
           var num1=parseInt(document.getElementById('num1').value);
           var num2=parseInt(document.getElementById('num2').value);
           if(isNaN(num1) || isNaN(num2)){
               alert('请输入数字');
               return false;
           }
           result.value=func(num1,num2);
       }


       function add(num1,num2){//加法
           return num1+num2;
       }
       function sub(num1,num2){//减法
           return num1-num2;
       }
       function mul(num1,num2){//乘法
           return num1*num2;
       }
       function div(num1,num2){//除法
           if(num2==0){
               alert('除数不能小于等于0');
               return '';
           }
           return num1/num2;
       }

    </script>
    
</body>
</html>